package pers.lance.merchant.jms;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;
import pers.lance.merchant.pojo.Customer;
import pers.lance.merchant.util.JsonUtil;

import javax.jms.*;
import java.util.Currency;

/**
 * @ Author     ：LILA3
 * @ Date       ：Created in 9:31 PM 7/30/2018
 */
@Component
public class JmsSender {
    @Autowired
    JmsTemplate jmsTemplate;
    @Autowired
    Queue queue;

    public void send(final Customer customer) {
        jmsTemplate.send(queue, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                Message message = null;
                try {
                    String jsonStr = JsonUtil.obj2json(customer);
                    message = session.createTextMessage(jsonStr);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return message;
            }
        });
    }

}
